//********************************************************************************************************************//
//ORGANIZATION:
//AUTHOR: bpeng(bogers.peng@gmail.com)
//SUMMARY:
//********************************************************************************************************************//
#include "../Comment.h"

using namespace Native::Compiling;
using namespace Native::Compiling::Sql;

CComment::CComment()
{
}

CComment::CComment(C_COMMENT& that) :
    CField(that),
    _style(that._style),
    _content(that._content)
{
}

CComment::CComment(C_COMMENT&& that) :
    CField(that),
    _style(that._style),
    _content(that._content)
{
}

CComment::~CComment()
{
}

wstring CComment::ToString() const
{
    wchar_t cstring[128] = {0};
    wstring string(CField::ToString());

    wsprintf(cstring, L"Style:[%d], Content:[%s]", _style, _content.ToCString());

    string.append(L",");
    string.append(cstring);

    return move(string);
}

bool CComment::operator==(C_COMMENT& rvalue) const
{
    return
        CField::operator==(rvalue) &&
        _style == rvalue._style &&
        _content == rvalue._content;

}

bool CComment::operator!=(C_COMMENT& rvalue) const
{
    return !operator==(rvalue);
}

void CComment::Clear()
{
    CField::Clear();

    _style = STYLE_SINGLE;
    _content = EMPTY_STRING;
}

CString CComment::ToCode() const
{
    CString code;

    switch (_style)
    {
    case STYLE_SINGLE:
        {
            code.Append(L"--");
        }
        break;
    case STYLE_MULTI:
        {
            code.Append(L"/*");
        }
        break;
    }

    code.Append(_content.ToString());
    if (STYLE_MULTI == _style) {
        code.Append(L"*/");
    }

    return move(code);
}


C_COMMENT& CComment::operator=(C_COMMENT& rvalue)
{
    CField::operator=(rvalue);

    _style = rvalue._style;
    _content = rvalue._content;

    return *this;
}
